var app = getApp();
var that
Page({
  data: {
    currentTab: 0,
    currentTab_goods:0,
    orders:{},
    ordersss:{},
    has_orders:false,//初始设置没有订单
  },
  onLoad: function (options) {
    that = this
    that.get_orders()
    // Do some initialize when page load.
  },
  onReady: function () {
    // Do something when page ready.
  },
  onShow: function () {
    that.get_orders()
  },
  //改变选项卡
  bindChange: function (e) {
    that.setData({ currentTab: e.detail.current });
  },
 
  //选项卡标题绑定的事件
  swichNav: function (e) {
    if (that.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      var current = e.target.dataset.current;
      that.setData({
        currentTab: parseInt(current),
      });
    };
  },
  navigateToOrder:function(e){
    if (that.data.currentTab_goods === e.currentTarget.dataset.status) {
      return false;
    } else {
      var cur = e.currentTarget.dataset.status;
      that.setData({
        currentTab_goods: parseInt(cur),
      });
    };
  },
  warm:function(){  //点击下单
    wx.switchTab({
      url: '../home/home'
    })
  },
  house_m:function(e){//跳到预约房间的详情
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../advance/advance?ordersn='+that.data.orders[id].order.ordersn,
    })
  },
  server_m: function (e) {//跳到猫咪下单 的详情
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: './ser_order?ordersn=' + that.data.orders[id].order.ordersn,
    })
  },
  get_orders:function(){
    app.req("get_orders.html", { "openid": app.data.openid},function(res){
      if (res.status == "success") {
        that.setData({ orders: res.mess });
        if (that.data.orders.length>0)//长度大于0说明有订单
        {  that.setData({ has_orders: true }); }

      } else if (res.status == "error") {
        app.toast(res.mess)
      } else {
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.get_orders()
          }
        })
      }
    })
  }
})
